(function($) {
	$.fn.vitoat = function() {
		if(typeof arguments[0]=='string'){
			return $.fn.vitoat.methods[arguments[0]].apply(this,Array.prototype.slice.call(arguments,1));
		}
		var opt = $.extend(true,{},$.fn.vitoat.defaults,arguments[0]);
		if (opt.data == undefined || opt.data == null || opt.data.length == 0) {
			if (opt.url && opt.url != null) {
				$.ajax({
					url: opt.url,
					data:{},
					async: false,
					dataType:"json",
					success:function(data){
						opt.data = data.data;
						opt.limit = data.data.length;
					}
				});
			}
		}
		$(this).atwho('setIframe', window.parent.document.getElementsByName("mainFrame")[0], true);
		$(this).atwho(opt);
	}
	$.fn.vitoat.defaults = {
		at: "@", //
		displayTpl: "<li>${name}</li>", //显示模板
		insertTpl: '<span style="color: rgb(57, 141, 238);" class="vitoat-id" data-id="${id}">@${name}</span>',//插入模板
		startWithSpace: false,//是否已空格开始
		data: null,
		url: BASEPATH+'/oa/oauser/getCompanyUserList.htm'
	}
	$.fn.vitoat.methods = {
		getText: function() {
			return $(this).html();
		},
		getIds: function() {
			var ids = [];
			if ($(this).find('.vitoat-id')) {
				$(this).find('.vitoat-id').each(function(i, n){
					ids.push($(n).data('id'));
				});
			}
			return ids;
		}
	}
})($);